package com.xing.binbackend.pattern.responsibility.ecommerce.product.process;

import com.xing.binbackend.pattern.responsibility.ecommerce.product.ChainBizMarkEnum;
import com.xing.binbackend.pattern.responsibility.ecommerce.product.MerchantAdminAbstractChainHandler;
import com.xing.binbackend.pattern.responsibility.ecommerce.product.ProductUpShelfReqDTO;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class ProductInfoNotNullChainFilter implements MerchantAdminAbstractChainHandler<ProductUpShelfReqDTO> {
    @Override
    public void handler(ProductUpShelfReqDTO requestParam) {
        if (!StringUtils.hasLength(requestParam.getProductName())) {
            throw new RuntimeException("商品名称不能为空！");
        }
        if (requestParam.getPrice() <= 0) {
            throw new RuntimeException("商品价格必须大于0！");
        }
        System.out.println("商品信息非空校验通过");
    }

    @Override
    public int getOrder() {
        return 1;
    }

    @Override
    public String mark() {
        return ChainBizMarkEnum.MERCHANT_ADMIN_PRODUCT_UPSHELF_KEY.name();
    }
}